<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 作业1
        // 数组去重(做法1)
        var myArr = [46,1, 2, 3, 1, 2, 3,5, 6,7,2,3, 0, 0];
        // Array.prototype.unique = function(){
        //     var cur = 0;
        //     for(var i = 0; i < this.length; i++){
        //         cur = this[i];
        //         for(var j = i + 1; j < this.length; j++){
        //             if(cur == this[j]){
        //                 this.splice(j, 1);
        //                 j--;
        //                 i--;
        //             }
        //         }
        //     }
        //     return this;
        // }
        
        Array.prototype.unique = function(){
            var temp = {},
                newArr = [];
            for(var i = 0; i < this.length; i++){
                // if(!temp[this[i]]){
                //     temp[this[i]] = 'this[i]';
                //     newArr.push(this[i]);
                // }
                if(!temp.hasOwnProperty(this[i])){
                    temp[this[i]] = this[i];
                    newArr.push(this[i]);
                    // 如果是字符串的话，则用拼接
                }
            }
            return newArr;
        }

        console.log(myArr.unique());

        // 作业2
        // 判断类型
        ;(function(){
            function myTypeof(val){
                if(val === null) return 'null';
                var typeVal = typeof(val),
                    toStr = Object.prototype.toString,
                    res = {
                        '[object Array]': 'array',
                        '[object Object]': 'object',
                        '[object Number]': 'object number',
                        '[object String]': 'object string',
                        '[object Boolean]': 'object boolean',
                    };
                if(typeVal === 'object'){
                    return res[toStr.call(val)];
                }
                return typeVal;
            }

            window.myTypeof = myTypeof;
        })();

        console.log(myTypeof(1));
    </script>
</body>
</html>